#!/bin/bash
# Trigger one OBS project's packages _service
#

if [ $# -ne 2 ]; then
        echo "Usage: trigger-services.sh PROJECT pkg-list"
        exit 1
fi

#osc api /source/$1 | cut -s -f2 -d\" | sed '1d'| sort -s > z1
pkgs=($(cat $2))

declare -i i=0
for ((j=0; j<20 && i<${#pkgs[@]}; i++, j++)); do
        osc service remoterun $1 ${pkgs[$i]} &
done >/dev/null	# drop "ok" messages
for ((; i<${#pkgs[@]}; i++)); do
        wait -n
        osc service remoterun $1 ${pkgs[$i]} &
done >/dev/null	# drop "ok" messages
wait

#osc rebuild --all $1
#osc api -X POST /source/$1?cmd=set_flag\&flag=build\&status=enable\&repository=standard_riscv64
